package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Morten
 */
public class DB {
    
    private Connection connection;
    private Statement statement;
    
    /**
     * Login
     * @param host
     * @param port
     * @param user
     * @param pass
     * @return 
     */
    public final int login(String host, String port,String user,String pass){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/naestvedauction", user, pass);
            statement=connection.createStatement();
        } catch (ClassNotFoundException ex) {
            System.out.println("Class not found: " + ex.getMessage());
	    return 20000;
        } catch (SQLException ex) {
            System.out.println("Cant make the connection: " + ex.getMessage()+"\nErrorcode: "+ex.getErrorCode());
	    return ex.getErrorCode();
        }
	return 10000;
    }
    public final Statement getStatement(){
	return statement;
    }
}
